|
|
|
Before talking
about operators, we'll take a quick aside into booleans, since we'll need to
know what a boolean is before discussing operators. A boolean value is one
that can be either true or false. No other values are allowed. Booleans and
boolean operations are at the heart of programming. Many times in a program,
you'll want to do one thing if a certain condition is true, and a different
thing if the condition is false. For example, when processing a series of
checkboxes, you may want to take an action only if a box is checked, and do
nothing otherwise. That's when you'll want to use a boolean.
|
|
Most programming
languages have a type for booleans, usually called "boolean" or
"bool". Some C++ compilers recognize the type bool, others do not. For now, assume that your compiler supports the bool type. We'll discuss what to do if your compiler doesn't, in a moment.
|
|
In order to use
boolean logic to your advantage, you need to learn about the three basic
boolean operations. They are called and, or, and not. Each operation takes
either one or two boolean inputs, and returns a boolean output. They are
often represented by symbols known as "gates", shown above.
|
|
|
|
|